package week07

// 680. 验证回文字符串 Ⅱ
// https://leetcode-cn.com/problems/valid-palindrome-ii/

func validPalindrome(s string) bool {
	return isPalindrome(s, 0, len(s)-1, true)
}

func isPalindrome(s string, l, r int, canDel bool) bool {
	for l < r {
		if s[l] != s[r] {
			if canDel {
				if isPalindrome(s, l+1, r, false) || isPalindrome(s, l, r-1, false) {
					return true
				}
			}
			return false
		}
		l++
		r--
	}
	return true
}
